package com.zfx.mapper;

import com.zfx.pojo.Address;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @description:  通讯录模块持久层接口
 * @author: zfx
 */
public interface IAddressMapper extends Mapper<Address> {

    @Select("<script>select * from tbs_tongxunlu where userId=#{userId} " +
            "<if test='nickName != null'> and nickname like #{nickName}</if>" +
            "<if test='remarks != null'> and remarks like #{remarks}</if>" +
            "<if test='phone != null'> and phone like #{phone}</if></script>")
    public List<Address> findByAddress(Address address);

    @Select("<script>select count(*) from tbs_tongxunlu where userId=#{userId} " +
            "<if test='nickName != null'> and nickname like #{nickName}</if>" +
            "<if test='remarks != null'> and remarks like #{remarks}</if>" +
            "<if test='phone != null'> and phone like #{phone}</if></script>")
    public int countByAddress(Address address);

    @Select("select * from tbs_tongxunlu where userId=#{userId} and haoyouId=#{haoyouId}")
    public Address existsWithUserIdAndHaoyouId(Address address);
}
